import { Provide } from '@midwayjs/decorator';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { Repository } from 'typeorm';
import { BaseService } from '../../../common/base.service';
import { DictManageEntity } from '../entity/dictManage';

@Provide()
export class DictManageService extends BaseService<DictManageEntity> {
  @InjectEntityModel(DictManageEntity)
  dictManageModel: Repository<DictManageEntity>;

  getModel(): Repository<DictManageEntity> {
    return this.dictManageModel;
  }

  async getDictOptions(type: string) {
    const rut = await this.list({ type: type || null })
    return rut.map(item => {
      return { ...item, label: item.name, value: item.code }
    })
  }
}